//
//  HWGameCircleHttpManager.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/30.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit
import Alamofire
import SwiftUI
class HWGameCircleHttpManager: NSObject {
    var uid = HWLocallyStoredData.getLoginUserID()
    var tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
    var p = 1
    var max_p = "1"
}

extension HWGameCircleHttpManager {
    /// sign加密
    /// - Returns: sign
    func encrySign() -> String {
        
        let sign = "\(uid)\(tStr)\("fsd213ewdsadqwe2121213edsad")"
        let signMD5 = WMUtil.md5HexDigest(sign) ?? ""
        return signMD5
    }
    func headers() -> HTTPHeaders {
//        let tStr = Date().timeStamp
//        let signature = "nnmitu"+tStr
//
//        let json = ["usersid":HWLocallyData.getUsersID(),"timestamp":tStr,"signature":signature.DDMD5Encrypt(.lowercase32)]
//        let jsonString = HWPublicFuncTools.convertDictionAryToJson(dic: json as NSDictionary)
//        let aesStr:String = aesEncryptString(jsonString, "NrrynIXcpucYvGSk")
        let header:HTTPHeaders = ["eaua":JJUUIDManager.getUUID(),"imei":ASIdentifierManager.shared().advertisingIdentifier.uuidString]
        
        return header
    }
}

extension HWGameCircleHttpManager {
    ///圈子列表
    func getGameCircleList(success:@escaping (_ :[HWGameCircleModel]) -> Void, failure:@escaping(_ :String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode(),
            "p":"1",
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCircle)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCircleModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as? [HWGameCircleModel] ?? [])
                        }
                        
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    /// 圈子列表加载更多
    func getGameCircleListFooter(success:@escaping (_ :[HWGameCircleModel]) -> Void, failure:@escaping(_ :String)->Void){
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode(),
            "p":"\(p)",
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCircle)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCircleModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as? [HWGameCircleModel] ?? [])
                        }
                        
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        self.p -= 1
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    self.p -= 1
                    print("没有获取到数据")
                    
                }
                
            }else {
                self.p -= 1
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    /// 圈子群组
    func getGameCircleGroup(success:@escaping (_ :[HWGameCircleGroupModel]) -> Void, failure:@escaping(_ :String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode(),
            "p":"1",
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCircleChatGroup)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCircleGroupModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as? [HWGameCircleGroupModel] ?? [])
                        }
                        
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    /// 推荐游戏
    func getGameCircleRecommend(success:@escaping (_ :[HWGameCircleModel]) -> Void, failure:@escaping(_ :String)->Void){
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode(),
            "ios":"1",
            "p":"1",
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCircleRecommendGame)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWGameCircleModel].deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model as? [HWGameCircleModel] ?? [])
                        }
                        
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 上传图片
    /// - Parameters:
    ///   - uploadImage: 图片
    ///   - success: 成功
    ///   - failure: 失败
    func uploadImage(uploadImage:UIImage,success:@escaping ((_ urlString:String) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let headers: HTTPHeaders = [
            "Content-type": "multipart/form-data",
            "Host": HWGlobalConst.shared.host,
            "Transfer-Encoding": "chunked",
        ]

        
        AF.upload(multipartFormData: { multipartFormData in
            let data = uploadImage.jpegData(compressionQuality: 0.5)
            multipartFormData.append(Data(data!), withName: "image", fileName: "123.png", mimeType: "image/png")
            multipartFormData.append(Data(self.uid.utf8), withName: "uid")
            multipartFormData.append(Data(self.tStr.utf8), withName: "t")
            multipartFormData.append(Data(self.encrySign().utf8), withName: "sign")
        }, to: URL_Upload, headers: headers)
            .responseJSON { response in
                debugPrint(response)
                if response.data != nil {
                    let result = HWUniversal.DataToJSONString(data: response.data ?? Data())
                    success(result ?? "")
//                    let result:NSDictionary = response.value as? NSDictionary ?? [:]
//
//                    if result["code"] as? Int == 1 {
//                        success(result["data"] as! String)
//                    }else{
//
//                    }
                    
                }else {
                    print("获取数据失败")
                    
                }
            }
    }
    /// 上传视频
    /// - Parameters:
    ///   - uploadImage: 视频
    ///   - success: 成功
    ///   - failure: 失败
    func uploadVideo(record:Data,suffix:String,success:@escaping ((_ urlString:String) -> Void), failure: @escaping((_ errorMessage: String) -> Void),progress: @escaping((_: String) -> Void)) {
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        
        AF.upload(multipartFormData: { multipartFormData in
            //            let data = uploadImage.jpegData(compressionQuality: 0.5)
            multipartFormData.append(record, withName: "image", fileName: "123.\(suffix)", mimeType: "audio/wav")
            multipartFormData.append(Data(self.uid.utf8), withName: "uid")
            multipartFormData.append(Data(self.tStr.utf8), withName: "t")
            multipartFormData.append(Data(self.encrySign().utf8), withName: "sign")
        }, to: URL_Upload)
            .responseJSON { response in
                debugPrint(response)
                if response.data != nil {
                    let result = HWUniversal.DataToJSONString(data: response.data ?? Data())
                    success(result ?? "")
//                if response.value != nil {
//                    let result:NSDictionary = response.value as? NSDictionary ?? [:]
//                    if result["code"] as? Int == 1 {
//                        success(result["data"] as! String)
//                    }else{
//
//                    }
                    
                }else {
                    print("获取数据失败")
                    
                }
            }
            .uploadProgress { pros in
                print(pros.fractionCompleted)
                let str = String(format: "%.f", pros.fractionCompleted * 100)
                progress(str)
            }
    }
    
    /// 发布动态
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - id: <#id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func setTakeALookRelease(para:NSMutableDictionary,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        para.setValue(uid, forKey: "uid")
        para.setValue(tStr, forKey: "t")
        para.setValue(encrySign(), forKey: "sign")
        
        AF.request(URL(string: URL_TakeALookRelease)!, method: .get, parameters: para as? Parameters).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
                    //                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
                
            }
        }
    }
    
    /// 动态详情
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - live_id: <#live_id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func getTakeALookDetailData(id:String,is_look:String,success:@escaping ((_ :HWGameCircleModel) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {

        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "is_look":is_look,
            
        ]
        AF.request(URL(string: URL_TakeALookDetail)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        if let models = HWGameCircleModel.deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models)
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        }
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")

                }
                
            }else {
                print("获取数据失败")
                
            }
        }
        
    }
    
    /// 动态评论列表
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - live_id: <#live_id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func getTakeALookCommentList(id:String,success:@escaping ((_ :[HWTakeALookCommentModel]) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "p":"\(p)",
            "num":"20"
        ]
        AF.request(URL(string: URL_TakeALookCommentList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        if let models = [HWTakeALookCommentModel].deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models as! [HWTakeALookCommentModel])
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        }
                    } else if resultDic["code"] as? Int == 100 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")

                }
                
            }else {
                print("获取数据失败")
                
            }
        }
        
    }
    
    /// 评论列表加载更多
    /// - Parameters:
    ///   - id: <#id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func getTakeALookCommentListFooter(id:String,success:@escaping ((_ :[HWTakeALookCommentModel]) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "p":"\(p)",
            "num":"20"
        ]
        AF.request(URL(string: URL_TakeALookCommentList)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        if let models = [HWTakeALookCommentModel].deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models as! [HWTakeALookCommentModel])
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        }
                    } else if resultDic["code"] as? Int == 100 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
                    self.p -= 1

                }
                
            }else {
                print("获取数据失败")
                self.p -= 1
                
            }
        }
        
    }
    
    /// 动态点赞
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - id: <#id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func setTakeALookZan(type:String,id:String,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "type":type,
            "id":id,
        ]
        AF.request(URL(string: URL_TakeALookZan)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 100 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
        
    }
    
    /// 动态评论详情列表
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - live_id: <#live_id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func getTakeALookCommentDetailList(id:String,success:@escaping ((_ :[HWTakeALookCommentModel]) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {
        p = 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "p":"\(p)",
            "num":"20"
        ]
        AF.request(URL(string: URL_TakeALookCommentDetailList)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        if let models = [HWTakeALookCommentModel].deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models as! [HWTakeALookCommentModel])
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        }
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")

                }
                
            }else {
                print("获取数据失败")
                
            }
        }
        
    }
    
    /// 动态评论详情列表
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - live_id: <#live_id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func getTakeALookCommentDetailListFooter(id:String,success:@escaping ((_ :[HWTakeALookCommentModel]) -> Void), failure: @escaping((_ errorMessage: String) -> Void)) {
        p += 1
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":id,
            "p":"\(p)",
            "num":"20"
        ]
        AF.request(URL(string: URL_TakeALookCommentDetailList)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        if let models = [HWTakeALookCommentModel].deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models as! [HWTakeALookCommentModel])
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                            self.p -= 1
                        }
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        self.p -= 1
                    }
                    
                    
                }else {
                    print("没有获取到数据")
                    self.p -= 1

                }
                
            }else {
                print("获取数据失败")
                self.p -= 1
                
            }
        }
        
    }
    
    /// 动态评论
    /// - Parameters:
    ///   - type: <#type description#>
    ///   - id: <#id description#>
    ///   - success: <#success description#>
    ///   - failure: <#failure description#>
    func setTakeALookReplyComment(dongtai_id:String,pid:String,ppid:String,content:String,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "dongtai_id":dongtai_id,
            "pid":pid,
            "ppid":ppid,
            "content":content
        ]
        AF.request(URL(string: URL_TakeALookReplyComment)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
        
    }
    
    /// 标签
    /// - Parameters:
    ///   - success: model
    ///   - failure: error
    func getGameCircleConfig(success:@escaping (_ :HWGameCircleConfigModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_GameCircleConfig)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? String == "1" {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWGameCircleConfigModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 删除动态
    func deleteDynamic(dongtai_id:String,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":dongtai_id,
        ]
        AF.request(URL(string: URL_DeleteDynamic)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
    }
    
    /// 举报
    func reportDynamic(dongtai_id: String,remark: String,success:@escaping ((_:String) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "id":dongtai_id,
            "os":"4",
            "remark":remark,
            "type":"1",
        ]
        AF.request(URL(string: URL_report)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                    
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
    }
    
    /// 搜索游戏
    func dynamicSearchGame(keyword: String,success:@escaping ((_:[HWDynamicGameModel]) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "keyword":keyword,
        ]
        AF.request(URL(string: URL_searchGame)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as? Int == 1 {
                        if let model = [HWDynamicGameModel].deserialize(from: result ,designatedPath: ".data") {
                            success(model as! [HWDynamicGameModel])
                        }
                            
                    }else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
    }
    
    /// 搜索话题
    func dynamicSearchTopic(keyword: String,success:@escaping ((_:[HWDynamicGameModel]) -> Void), failure: @escaping((_: String) -> Void)) {
        
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "keyword":keyword,
        ]
        AF.request(URL(string: URL_searchTopic)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "﻿" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as? Int == 1 {
                        if let model = [HWDynamicGameModel].deserialize(from: result ,designatedPath: ".data") {
                            success(model as! [HWDynamicGameModel])
                        }
                            
                    }else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
//                    self.p -= 1
                }
                
            }else {
                print("获取数据失败")
//                self.p -= 1
                
            }
        }
    }
}
